phyloPereira <- read.tree('https://ars.els-cdn.com/content/image/1-s2.0-S1055790316304316-mmc2.nwk')
turt<-read.table("Data_turt.txt", header = T, row.names=1)
name.check(phyloPereira,turt)###############
library("RRphylo")
name.check(phyloPereira,turt)###############
library(geiger)
library(phytools)
name.check(phyloPereira,turt)###############
phyloPereira <- read.tree('https://ars.els-cdn.com/content/image/1-s2.0-S1055790316304316-mmc2.nwk')
name.check(phyloPereira,turt)###############
species<- turt$Species
cut<-name.check(phyloPereira,turt)
cut2<-as.vector(cut$tree_not_data)
pruned.tree<- drop.tip(phyloPereira, cut2, trim.internal = TRUE, subtree = FALSE,
root.edge = 0)
name.check(pruned.tree,turt)
clutchyear_mean <- ((turt$clutchesyearmax + turt$clutchesyearmin)/2) #Mean number of clutches per year
FEC<- as.vector(turt$clutchmax*clutchyear_mean)
ESH<- as.vector((turt2$egglenght/turt2$eggwidth)/turt$carapace)
ESH<- as.vector((turt$egglenght/turt$eggwidth)/turt$carapace)
class(ESH)
class(ESH)
turt3<-cbind(ESH, ESI)
class(turt3)
rownames(turt3) <- rownames(turt2)
head(turt3)
clutchyear_mean <- ((turt$clutchesyearmax + turt$clutchesyearmin)/2) #Mean number of clutches per year
FEC<- as.vector(turt$clutchmax*clutchyear_mean)
ESH<- as.vector((turt$egglenght/turt$eggwidth)/turt$carapace)
turt.cor<-cbind(ESH, ESI)
turt.cor<-cbind(ESH, FEC)
class(turt.cor)
rownames(turt.cor) <- rownames(turt)
head(turt.cor)
Q1<-evolvcv.lite(pruned.tree, turt3)
Q1<-evolvcv.lite(pruned.tree, turt.cor)
FEC<- as.vector(1/(turt$clutchmax*clutchyear_mean))
turt.cor<-cbind(ESH, FEC)
rownames(turt.cor) <- rownames(turt)
head(turt.cor)
Q1<-evolvcv.lite(pruned.tree, turt.cor)
Q1
clutch.FEC<-as.matrix(turt$clutchmax)
rownames(clutch.FEC) <- rownames(turt)
threesizes<- as.array(cut(clutch.FEC, breaks = c(0, 4,29, Inf), labels = c(1:3)))
rownames(threesizes) <- rownames(turt)
threesizes
three_size_mapped_tree <- make.simmap(pruned.tree,threesizes, model="ARD", nsim=1)
cols<-setNames(c("blue","coral", "green"),c("1", "2", "3"))
plot(three_size_mapped_tree, cols, ftype="i", fsize=0.2)
legend("bottomleft", c("small", "medium", "large"), fill=c("blue","coral", "green"))
ESI<- turt$egglenght/turt2carap
ESI<- turt$egglenght/turt$carap
ESH<- as.vector(turt$egglenght/turt$eggwidth)
turt.cor<-cbind(ESH, ESI)
class(turt.cor)
rownames(turt.cor) <- rownames(turt)
head(turt.cor)
Q1<-evolvcv.lite(three_size_mapped_tree, turt.cor)
Q1
data(sunfish.tree)
data(sunfish.data)
sunfish.fit<-evolvcv.lite(sunfish.tree,sunfish.data[,2:3])
sunfish.fit
Q1<-evolvcv.lite(three_size_mapped_tree, turt.cor, models="all models")
install.packages("phytolls")
library(phytools)
Q1<-evolvcv.lite(three_size_mapped_tree, turt.cor, models="all models")
Q1<-evolvcv.lite(three_size_mapped_tree, turt.cor, models="all models")
Q1<-evolvcv.lite(three_size_mapped_tree, turt.cor, models="2b")
PhyloThompson <-read.tree("GeoHISSEInput.tree")
library("RRphylo")
library(geiger)
library(phytools)
PhyloThompson <-read.tree("GeoHISSEInput.tree")
plotTree(phyloThompson)
plotTree(PhyloThompson)
class(phyloThompson)
class(PhyloThompson)
plotTree(PhyloThompson, fsize=0.9)
phyloThompson <-read.tree("GeoHISSEInput.tree")
plotTree(phyloThompson, fsize=0.9)
turt<-read.table("Data_turt.txt", header = T, row.names=1)
name.check(phyloThompson,turt)###############
phyloThompson <-read.tree("GeoHISSEInput.tree.txt")
plotTree(phyloThompson, fsize=0.9)
turt<-read.table("Data_turt.txt", header = T, row.names=1)
name.check(phyloThompson,turt)###############
phyloThompson <-read.tree("GeoHISSEInput.tree.txt")
plotTree(phyloThompson, fsize=0.9)
turt<-read.table("Data_turt.txt", header = T, row.names=1)
name.check(phyloThompson,turt)###############
phyloThompson <-read.tree("GeoHISSEInput.tree.txt")
plotTree(phyloThompson, fsize=0.9)
turt<-read.table("Data_turt.txt", header = T, row.names=1)
name.check(phyloThompson,turt)###############
phyloPereira <- read.tree('https://ars.els-cdn.com/content/image/1-s2.0-S1055790316304316-mmc2.nwk')
turt<-read.table("Data_turt.txt", header = T, row.names=1)
name.check(phyloPereira,turt)###############
name.check(phyloThompson,turt)###############
#Prune Tree
species<- turt$Species
cut<-name.check(phyloThompson,turt)
cut2<-as.vector(cut$tree_not_data)
pruned.tree<- drop.tip(phyloThompson, cut2, trim.internal = TRUE, subtree = FALSE,
root.edge = 0)
name.check(pruned.tree,turt)
turt<-read.table("Data_turt_Thompson.txt", header = T, row.names=1)
name.check(phyloThompson,turt)###############
turt<-read.table("Data_turt_Thompson.txt", header = T, row.names=1)
name.check(phyloThompson,turt)###############
#Prune Tree
species<- turt$Species
cut<-name.check(phyloThompson,turt)
cut2<-as.vector(cut$tree_not_data)
pruned.tree<- drop.tip(phyloThompson, cut2, trim.internal = TRUE, subtree = FALSE,
root.edge = 0)
name.check(pruned.tree,turt)
phyloThompson <- read.tree("Thompson2021_edited.txt")
turt<-read.table("Data_turt_Thompson.txt", header = T, row.names=1)
name.check(phyloThompson,turt)###############
#Prune Tree
species<- turt$Species
cut<-name.check(phyloThompson,turt)
cut2<-as.vector(cut$tree_not_data)
pruned.tree<- drop.tip(phyloThompson, cut2, trim.internal = TRUE, subtree = FALSE,
root.edge = 0)
name.check(pruned.tree,turt)
clutch.FEC<-as.matrix(turt$clutchmax)
rownames(clutch.FEC) <- rownames(turt)
threesizes<- as.array(cut(clutch.FEC, breaks = c(0, 4,29, Inf), labels = c(1:3)))
rownames(threesizes) <- rownames(turt)
three_size_mapped_tree <- make.simmap(pruned.tree,threesizes, model="ARD", nsim=1)
cols<-setNames(c("blue","coral", "green"),c("1", "2", "3"))
# plot the mapped ancestral states
plot(three_size_mapped_tree, cols, ftype="i", fsize=0.2)
# add a legend
legend("bottomleft", c("small", "medium", "large"), fill=c("blue","coral", "green"))
#Relative egg size (ESI): egg length/carapace length
#Egg shape (ESH):egg length/egg width
ESI<- turt$egglenght/turt$carap
ESH<- as.vector(turt$egglenght/turt$eggwidth)
turt.cor<-cbind(ESH, ESI)
rownames(turt.cor) <- rownames(turt)
Q1<-evolvcv.lite(three_size_mapped_tree, turt.cor)
Q1
cov2cor(Q1$model1$R)
cov2cor(Q1$model2$R$`1`)
cov2cor(Q1$model2$R$`2`)
cov2cor(Q1$model3$R$`1`)
cov2cor(Q1$model3$R$`2`)
cov2cor(Q1$model3$R$`3`)
cov2cor(Q1$model4$R$`1`)
cov2cor(Q1$model4$R$`2`)
cov2cor(Q1$model4$R$`3`)
phylomorphospace(three_size_mapped_tree,turt.cor,colors=cols,
ftype="off",bty="n",lwd=3,node.size=c(0,1.5),
node.by.map=TRUE,xlab="Egg size",
ylab="Egg shape")
legend("topleft",c("Small clutch","Medium clutch", "Large clutch"),
pch=21,pt.cex=2,pt.bg=cols,bty="n")
title(main="Phylomorphospace plot of turtles egg strategies",font.main=3)
turtT<-read.table("TxT.txt", header = T, row.names=1)
phyloPereira <- read.tree('https://ars.els-cdn.com/content/image/1-s2.0-S1055790316304316-mmc2.nwk')
turt<-read.table("Data_turt.txt", header = T, row.names=1)
name.check(phyloPereira,turt)###############
library("RRphylo")
library(geiger)
library(phytools)
phyloPereira <- read.tree('https://ars.els-cdn.com/content/image/1-s2.0-S1055790316304316-mmc2.nwk')
turt<-read.table("Data_turt.txt", header = T, row.names=1)
name.check(phyloPereira,turt)###############
#Prune Tree
species<- turt$Species
cut<-name.check(phyloPereira,turt)
cut2<-as.vector(cut$tree_not_data)
pruned.tree<- drop.tip(phyloPereira, cut2, trim.internal = TRUE, subtree = FALSE,
root.edge = 0)
name.check(pruned.tree,turt)
turtT<-read.table("TxT.txt", header = T, row.names=1)
name.check(pruned.tree,turtT)
turtT<-read.table("TxT.txt", header = T, row.names=1)
name.check(pruned.tree,turtT)
TT<-as.array(turtT$Character)##################character states for clade convergence test
rownames(TT) <- rownames(turtT)
turtTT<-turt[,6]
head(turtTT)
turtT<-read.table("TxT.txt", header = TRUE, row.names=1)
name.check(pruned.tree,turtT)
TT<-as.array(turtT$Character)##################character states for clade convergence test
rownames(TT) <- rownames(turtT)
turtTT<-turtT[,6]
head(turtTT)
turt<-read.table("CryptoXPleuro_30eggs.txt", header = T, row.names=1)
name.check(pruned.tree,turt)
y<-as.array(turt$Character)##################character states for clade convergence test
rownames(y) <- rownames(turt)
turt2<-turt[,-c(4,5)]
head(turt2)
turtT<-read.table("TxT.txt", header = TRUE, row.names=1)
head(turtT)
TT<-as.array(turtT$Character)##################character states for clade convergence test
rownames(TT) <- rownames(turtT)
TT
turtTT<-turtT[,6]
turtTT
turtTT<-turtT[,-6]
turtTT
head(turtTT)
SC.state.T<-search.conv(tree=pruned.tree, y=turtTT, state=TT,min.dim=1,
filename = "Turt_TxT", declust = TRUE)
View(SC.state.T)
# Test convergence without group predetermination
turtT<-read.table("Threetraits.txt", header = TRUE, row.names=1)
name.check(pruned.tree,turtT)
TT<-as.array(turtT$Character)##################character states for clade convergence test
rownames(TT) <- rownames(turtT)
turtTT<-turtT[,-6]
head(turtTT)
SC.state.T<-search.conv(tree=pruned.tree, y=turtTT, state=TT,min.dim=1,
filename = "Turt_TxT", declust = TRUE)
turtT<-read.table("TxT.txt", header = TRUE, row.names=1)
name.check(pruned.tree,turtT)
TT<-as.array(turtT$Character)##################character states for clade convergence test
rownames(TT) <- rownames(turtT)
turtTT<-turtT[,-6]
head(turtTT)
SC.state.T<-search.conv(tree=pruned.tree, y=turtTT, min.dim=1,min.dist ="node1",
filename = "Turt_TxT", declust = TRUE)
class(turtTT)
# Test convergence without group predetermination
TRR<-RRphylo(pruned.tree,turtTT,cov=NULL,rootV=NULL,aces=NULL,x1=NULL,aces.x1=NULL,clus=0.5)
SC.state.T<-search.conv(RR=TRR, tree=pruned.tree, y=turtTT, min.dim=1,min.dist ="node1",
filename = "Turt_TxT", declust = TRUE)
#Test convergence between cryptodirans and pleurodirans that produce clutches containing bellow 5 eggs, from 5 to 29 eggs, and 30 or more eggs.
turt3<-read.table("3states.txt", header = T, row.names=1)
name.check(pruned.tree,turt3)
turt3states<-as.array(turt3$Character)##################character states for clade convergence test
rownames(turt3states) <- rownames(turt3)
turtTres<-turt[,-4]
head(turtTres)
turt3
turt3states
turtTres
turtTres<-turt3[,-4]
head(turtTres)
SC.state.A<-search.conv(tree=pruned.tree, y=turtTres, state=turt3states,min.dim=1,
filename = "3states", declust = TRUE)
turtm<-read.table("CxP_medium.txt", header = T, row.names=1)
name.check(pruned.tree,turtm)
M<-as.array(turtm$Character)##################character states for clade convergence test
rownames(M) <- rownames(turtm)
turtMe<-turtm[,-4]
head(turtMe)
M
## search for convergence within species
SC.state.A<-search.conv(tree=pruned.tree, y=turtMe, state=M,min.dim=1,
filename = "CriptoXPleuro_Medium", declust = TRUE)
SC.state.A
SC.state.All<-search.conv(tree=pruned.tree, y=turtTres, state=turt3states,min.dim=1,
filename = "3states", declust = TRUE)
SC.state.All
influ <- influ_phyglm(eggsize~Climatic_zone+diet+log_clutch_mean, data = turt, phy = pruned.tree)
install.packages("sensiPhy")
library("sensiPhy")
influ <- influ_phyglm(eggsize~Climatic_zone+diet+log_clutch_mean, data = turt, phy = pruned.tree)
turt["eggsize"]<- eggsize
#Egg Size
eggsize <- turt$egglenght/turt$carap #Relative egg size
turt["eggsize"]<- eggsize
influ <- influ_phyglm(eggsize~Climatic_zone+diet+log_clutch_mean, data = turt, phy = pruned.tree)
turt<-read.table("turtPereira2.csv", header = T, row.names=1, sep=";")
influ <- influ_phyglm(eggsize~Climatic_zone+diet+log_clutch_mean, data = turt, phy = pruned.tree)
#EGG SIZE PGLS - clutch_mean
ggplot(turt, aes(clutch_mean)) + geom_density(col="red", fill="red") #not ok
ggplot(turt, aes(log(clutch_mean))) + geom_density(col="red", fill="red") #ok
turt["log_clutch_mean"]<- log(turt$clutch_mean)
influ <- influ_phyglm(eggsize~Climatic_zone+diet+log_clutch_mean, data = turt, phy = pruned.tree)
turt["log_clutch_mean"]<- log(turt$clutch_mean)
log_clutch_mean<- log(turt$clutch_mean)
turt$clutch_mean
turt
clutch_mean
#Clutch Mean
clutch_mean <- (turt$clutchmin+turt$clutchmax)/2 #Mean number of eggs per clutch
turt["clutch_mean"]<- clutch_mean
log_clutch_mean<- log(turt$clutch_mean)
influ <- influ_phyglm(eggsize~Climatic_zone+diet+log_clutch_mean, data = turt, phy = pruned.tree)
Climatic_zone
influ <- influ_phyglm(eggsize~turt$Climatic_zone+diet+log_clutch_mean, data = turt, phy = pruned.tree)
turt$Climatic_zone
eggsize
phyloPereira <- read.tree('https://ars.els-cdn.com/content/image/1-s2.0-S1055790316304316-mmc2.nwk')
plotTree(phyloPereira, fsize=0.9)
name.check(phyloPereira,turt) #not ok - more species in the tree than in the dataset
library("RRphylo")
library(geiger)
library(phytools)
plotTree(phyloPereira, fsize=0.9)
name.check(phyloPereira,turt) #not ok - more species in the tree than in the dataset
name.check(pruned.tree,turt) # ok
turt<-read.table("turtPereira2.csv", header = T, row.names=1, sep=";")
turt
turt<-read.table("turtPereira2_all.csv", header = T, row.names=1, sep=";")
#Egg Size
eggsize <- turt$egglenght/turt$carap #Relative egg size
turt["eggsize"]<- eggsize
#Clutch Mean
clutch_mean <- (turt$clutchmin+turt$clutchmax)/2 #Mean number of eggs per clutch
turt["clutch_mean"]<- clutch_mean
str(turt)
phyloPereira <- read.tree('https://ars.els-cdn.com/content/image/1-s2.0-S1055790316304316-mmc2.nwk')
name.check(phyloPereira,turt) #not ok - more species in the tree than in the dataset
cut<-name.check(phyloPereira,turt)
cut2<-as.vector(cut$tree_not_data)
pruned.tree<- drop.tip(phyloPereira, cut2, trim.internal = TRUE, subtree = FALSE, root.edge = 0)
name.check(pruned.tree,turt) # ok
pgls_eggsize<- gls(eggsize~Climatic_zone+diet+log_clutch_mean, data=turt, correlation=corPagel(1, pruned.tree), method="ML")
########## PGLS EGGSIZE ##########
library("nlme")
pgls_eggsize<- gls(eggsize~Climatic_zone+diet+log_clutch_mean, data=turt, correlation=corPagel(1, pruned.tree), method="ML")
turt["log_clutch_mean"]<- log(turt$clutch_mean)
pgls_eggsize<- gls(eggsize~Climatic_zone+diet+log_clutch_mean, data=turt, correlation=corPagel(1, pruned.tree), method="ML")
influ <- influ_phyglm(eggsize~Climatic_zone+diet+log_clutch_mean, data = turt, phy = pruned.tree)
influ <- influ_phyglm(eggsize~Climatic_zone, data = turt, phy = pruned.tree)
influ <- influ_phylm(eggsize~Climatic_zone, data = turt, phy = pruned.tree)
# To check summary results and most influential species:
summary(influ)
# Visual diagnostics for clade removal:
sensi_plot(influ)
# Most influential species
influ$influential.species
influ2<- influ_phylm(fecund~Climatic_zone+diet+eggsize, data = turt, phy = pruned.tree)
#Fecundity
clutchyear_mean <- ((turt$clutchesyearmax + turt$clutchesyearmin)/2) #Mean number of clutches per year
fecund <- turt$clutchmax*clutchyear_mean  #Maximum number of egg per clutch * Mean number of clutches per year
turt["fecund"]<- fecund
influ2<- influ_phylm(fecund~Climatic_zone+diet+eggsize, data = turt, phy = pruned.tree)
summary(influ2)
influ2$influential.species
turt["logfecund"]<- log(fecund)
influ2<- influ_phylm(log(fecund)~Climatic_zone+diet+eggsize, data = turt, phy = pruned.tree)
influ2$influential.species
influ <- influ_phylm(eggsize~Climatic_zone+diet+log_clutch_mean, data = turt, phy = pruned.tree)
# Most influential species
influ$influential.species
